package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

//新循环 foreach循环
public class NewForDemo {
    public static void main(String[] args) {
       /* String[] str={"1","2","3","4","5"};
        for (int i=0;i<str.length;i++){
            String line=str[i];
            System.out.println(line);
        }
        for (String line:str){
            System.out.println(line);
        }*/
        Collection<String> c=new ArrayList<>();
        c.add("1");
        c.add("2");
        c.add("3");
        c.add("4");
        System.out.println(c);

        for (String str:c){
           // String str=(String)o;
            System.out.println(str);
        }
        /*Iterator<String> it=c.iterator();
        while (it.hasNext()){
            String str=it.next();
            System.out.println(str);
        }*/
Iterator<String> it=c.iterator();
while (it.hasNext()){
    String str=it.next();
    System.out.println(str);
}






    }
}
